package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.assertTrue;

import java.net.Authenticator;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.SpringerPlugin;

import org.junit.Before;
import org.junit.Test;

public class SpringerPluginTest {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");
		Authenticator.setDefault(new TestAuthenticator());
		
		ExecutorService pool = Executors.newFixedThreadPool(1);
		Callable<Publication> springerPlugin = new SpringerPlugin("10.1007/s00348-004-0843-x");
		Future<Publication> futurespringerPluginResult = pool.submit(springerPlugin);

		newpub = futurespringerPluginResult.get();
	}

	@Test
	public void tests() {
		assertTrue(newpub.getUrl().startsWith("http://www.springerlink.com/content"));
		
		assertTrue(newpub.getAuthors().size() == 2);
		
		assertTrue(newpub.getAuthors().get(0).getAuthorLastName().equals("Fei") && newpub.getAuthors().get(1).getAuthorLastName().equals("Merzkirch"));
		
		assertTrue(newpub.getArticleTitle().equals("Investigations of the measurement accuracy of stereo particle image velocimetry"));
		
		assertTrue(newpub.getPublicationTitle().equals("Experiments in Fluids"));
		
		assertTrue(newpub.getPageNumbers().equals("559-565"));
		
		assertTrue(newpub.getVolumeNumber().equals("37"));
		
		assertTrue(newpub.getEdition().equals("4"));
	}
}

